package com.itheima.controller;

import com.itheima.po.InsertStudent;
import com.itheima.po.StudentPageParam;
import com.itheima.po.UpdateStudent;
import com.itheima.pojo.Result;
import com.itheima.service.StudentService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Resource
    StudentService studentService;
    /**
     * 学员列表查询
     */
    @GetMapping
    public Result selectStudent(StudentPageParam param) {
        return studentService.selectStudent(param);
    }

    /**
     * 添加学员
     */
    @PostMapping
    public Result insertStudent(@RequestBody InsertStudent student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        log.info("接收的插入student参数{}",student);
        return studentService.insertStudent(student);
    }

    /**
     * 删除学员
     */
    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable List<Integer> ids) {
        log.info("接收的删除id参数{}",ids);

        return studentService.deleteStudentByIds(ids);
    }

    /**
     * 根据Id查询学员
     */
    @GetMapping("/{id}")
    public Result selectStudentById(@PathVariable Integer id) {
        return studentService.selectStudentById(id);
    }

    /**
     * 修改学员
     */
    @PutMapping
    public Result updateStudent(@RequestBody UpdateStudent student) {
        student.setUpdateTime(LocalDateTime.now());
        return studentService.updateStudent(student);
    }

    /**
     * 违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable("id") Integer id,@PathVariable("score") Integer score){
        return studentService.violation(id,score);
    }


}
